﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace _2013_ece_csharp_snake
{
    [Serializable]
    class DataSend
    {
        //public Point head;

        public double headX;
        public double headY;
        public IList<PointF> body;
        public Point wall;
        public bool newWall;

        public DataSend(int x, int y)
        {
            headX = x;
            headY = y;

            newWall = false;

            body = new List<PointF>();
        }

        public static DataSend DeserializeFromString<TData>(string settings)
        {
            byte[] b = Convert.FromBase64String(settings);
            using (var stream = new MemoryStream(b))
            {
                var formatter = new BinaryFormatter();
                stream.Seek(0, SeekOrigin.Begin);
                return (DataSend)formatter.Deserialize(stream);
            }
        }

        public static string SerializeToString<dataSend>(dataSend settings)
        {
            using (var stream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, settings);
                stream.Flush();
                stream.Position = 0;
                return Convert.ToBase64String(stream.ToArray());
            }
        }
        
    }

   
}
